package com.scale.service.voice.config;

import com.scale.service.voice.service.VoiceTaskWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * 语音任务WebSocket配置
 * 使用Spring Boot 2.x兼容的WebSocket配置
 * @author crp
 * @since 2025-01-26
 */
@Configuration
@EnableWebSocket
public class VoiceWebSocketConfig implements WebSocketConfigurer {
    
    @Autowired
    private VoiceTaskWebSocketHandler voiceTaskWebSocketHandler;
    
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 🔧 修改为按用户管理的WebSocket端点
        registry.addHandler(voiceTaskWebSocketHandler, "/ws/voice-task/user/**")
                .setAllowedOrigins("*");
    }
}
